package com.imooc.web.controller;


import com.imooc.dto.User;
import com.imooc.dto.UserQuery;
import io.swagger.annotations.ApiOperation;
import org.apache.commons.lang.builder.ReflectionToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.social.connect.web.ProviderSignInUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.context.request.ServletWebRequest;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liaofuxing
 * @date 2019/03/11 0:59
 * @E-mail liaofuxing@outlook.com
 */

@RestController
@RequestMapping("/user")
public class UserController {

    @Autowired
    private ProviderSignInUtils providerSignInUtils;

    @PostMapping("/regist")
    public void regist(User user, HttpServletRequest request) {
        //不管是注册用户还是绑定用户,都会有一个唯一标识
        String userId = user.getUsername();
        providerSignInUtils.doPostSignUp(userId, new ServletWebRequest(request));

    }

    @RequestMapping(value = "/user", method = RequestMethod.GET)
    @ApiOperation("用户查询服务")
    // public List<User> findUser(@RequestParam(value = "username", required = false , defaultValue = "tom") String nickname){
    public List<User> findUser(UserQuery userQuery, Pageable pageable) {

        System.out.println(ReflectionToStringBuilder.toString(userQuery, ToStringStyle.MULTI_LINE_STYLE));
        System.out.println(pageable.getPageSize());
        List<User> users = new ArrayList();
        User user = new User();
        user.setUsername("111");
        users.add(user);
        users.add(user);
        users.add(user);
        return users;
    }
}
